package com.hxzy.tms.javamail;

import java.security.GeneralSecurityException;
import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.sun.mail.util.MailSSLSocketFactory;
/**
 *
 * */
public class MailUtil {
	public static void main(String[] args) throws  MessagingException, GeneralSecurityException {
		Properties properties = new Properties();
		properties.setProperty("mail.host", "smtp.qq.com");
		properties.setProperty("mail.smtp.auth","true");
		
		//qq邮箱的ssl加密
		MailSSLSocketFactory sf = new MailSSLSocketFactory();
		sf.setTrustAllHosts(true);
		properties.put("mail.smtp.ssl.enable", "true");
		properties.put("mail.smtp.ssl.socketFactory", sf);
		
		Authenticator authenticator = new Authenticator(){
			public PasswordAuthentication  getPasswordAuthentication(){
				return new PasswordAuthentication("1319687532@qq.com","vlyvawibbsribgee");
			}
		};
		Session session = Session.getDefaultInstance(properties, authenticator);
		
		Message message = new MimeMessage(session);
		
		
		message.setFrom(new InternetAddress("1319687532@qq.com"));
		
		message.setRecipient(RecipientType.TO, new InternetAddress("2889279388@qq.com"));
		
		message.setSubject("hello");
		
		String str = "苦水润喉： <br/>" +"<br/>";
		message.setContent(str, "text/html;charset=UTF-8");
		
		Transport.send(message);
	}
}
